package cn.csc.module.product.controller.app.category;

import cn.csc.framework.common.pojo.CommonResult;
import cn.csc.module.product.api.category.dto.CategoryRespDTO;
import cn.csc.module.product.controller.admin.category.vo.CategoryCreateReqVO;
import cn.csc.module.product.controller.admin.category.vo.CategoryRespVO;
import cn.csc.module.product.controller.app.category.vo.AppCategoryProductRespVO;
import cn.csc.module.product.controller.app.category.vo.AppCategorySearchReqVO;
import cn.csc.module.product.convert.category.CategoryConvert;
import cn.csc.module.product.dal.dataobject.category.CategoryDO;
import cn.csc.module.product.service.category.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigInteger;
import java.util.List;

import static cn.csc.framework.common.pojo.CommonResult.success;


/**
 * @author: 云隐
 * @Date: 2024/01/10
 **/
@Api(tags = "用户 APP - 类目")
@RestController("appCategoryController")
@RequestMapping("/product/category")
@Validated
@Slf4j
@Setter
public class AppCategoryController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping("/get")
    @ApiOperation("获得分类信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = BigInteger.class)
    public CommonResult<CategoryRespVO> getCategory(@RequestParam("id") BigInteger id) {
        CategoryDO category = categoryService.getCategory(id);
        return success(CategoryConvert.INSTANCE.convert(category));
    }

    @GetMapping("/list")
    @ApiOperation("获得分类集合信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = BigInteger.class)
    public CommonResult<List<CategoryRespDTO>> getCategoryList(@RequestParam("shopId") BigInteger shopId, @RequestParam("parentId") BigInteger parentId) {
        List<CategoryRespDTO> category = categoryService.listByShopIdAndParenId(shopId, parentId);
        return success(category);
    }


    @GetMapping("/listThird")
    @ApiOperation("获得分类集合信息")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = BigInteger.class)
    public CommonResult<List<CategoryRespDTO>> getCategoryProductListThird(@RequestParam("shopId") BigInteger shopId) {
        List<CategoryRespDTO> category = categoryService.listByShopIdAndProduct(shopId);
        return success(category);
    }

    @GetMapping("/recommend")
    @ApiOperation("获得一级分类并且商品数量要达到集合信息")
    public CommonResult<List<CategoryRespDTO>> recommend() {
        List<CategoryRespDTO> category = categoryService.recommendList();
        return success(category);
    }

    @GetMapping("/categorysecond")
    @ApiOperation("获得二级和三级分类并且有商品的类目信息")
    public CommonResult<List<CategoryRespDTO>> categorysecond(AppCategorySearchReqVO reqVO) {
        List<CategoryRespDTO> category = categoryService.selectCategoryByLevel(reqVO);
        return success(category);
    }

    @GetMapping("/getByCategoryId")
    @ApiOperation("根据类目ID获取子集有商品的所有的类目")
    public CommonResult<AppCategoryProductRespVO> geCategoryById(@Validated AppCategorySearchReqVO reqVO) {
        AppCategoryProductRespVO category = categoryService.geCategoryById(reqVO);
        return success(category);
    }

    @GetMapping("/markLable")
    @ApiOperation("获得首页精钢区的二级分类信息")
    public CommonResult<List<CategoryRespDTO>> markLable(CategoryCreateReqVO reqVO) {
        reqVO.setStatus(1);
        List<CategoryRespDTO> category = categoryService.markLable(reqVO);
        return success(category);
    }
}
